package com.qxzn.app.personalcenter.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.qxzn.app.bean.ContactsBean;
import com.qxzn.app.personalcenter.R;
import com.qxzn.app.personalcenter.R2;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class ContactsAdapter extends RecyclerView.Adapter<ContactsAdapter.ViewHolder> {

    private Activity activity;
    private List<ContactsBean.DataBean> dataList;
    private ContactsBean.DataBean item;
    private View.OnClickListener itemClick;

    public ContactsAdapter(Activity activity, List dataList) {
        this.activity = activity;
        this.dataList = dataList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(activity).inflate(R.layout.item_contacts, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        item = dataList.get(position);
        String remark = item.getMemRemarks();
        if (!TextUtils.isEmpty(remark)) {
            remark = "(" + remark + ")";
        } else {
            remark = "";
        }
        holder.name.setText(item.getMemName() + remark);
        holder.phone.setText(item.getMemPhone() + "");
        holder.itemView.setTag(position);
        holder.itemView.setOnClickListener(itemClick);
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    public void setItemClick(View.OnClickListener itemClick) {
        this.itemClick = itemClick;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R2.id.iv_head)
        ImageView ivHead;
        @BindView(R2.id.name)
        TextView name;
        @BindView(R2.id.phone)
        TextView phone;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
